package com.jgy.juc.number;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author 姜光远
 * @date 2023/3/8 20:05
 */
public class Number implements Runnable{

    static int num  = 0;
    ReentrantLock lock = new ReentrantLock();
    @Override
    public void run() {
        while (true){
            if (num>99){
                break;
            }else {
                lock.lock();
                try {
                    if (num % 2 != 0){
                        System.out.println(Thread.currentThread().getName()+"打印了"+num);
                    }
                    num++;
                } catch (Exception e) {
                    e.printStackTrace();
                }finally {
                    lock.unlock();
                }
            }
        }
    }
}
